home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9411 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: malloc question
  5. Date: 10 Mar 1996 11:03:25 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4huctt$arv@sparcserver.lrz-muenchen.de>
  9. References: <4htonk$350@news.hklink.net>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. alex@station.net (Alex Chu) writes:
  13.  
  14.  
  15. >Hi everybody,
  16.  
  17. >I have a question for the following snip C program.
  18.  
  19. >typedef struct item {
  20. >  int val;
  21. >  struct item *next;
  22. >} ITEM, *PITEM;
  23.  
  24. >main()
  25. >{
  26. >  PITEM head, current;
  27. >  head=(PITEM) malloc(sizeof(ITEM));
  28. >            ^^^^^^^
  29. >  head->val=1;
  30. >}
  31.  
  32. >I want to know why need to use the type casting PITEM in front of the
  33. >malloc ?  Please help!
  34.  
  35. Simple answer: You don't have to use that cast, and you should _not_ use
  36. it, because all you can do with that cast is _hide_ an error.
  37.  
  38. OTOH, if you are using a C++ compiler to translate C programs, the cast
  39. is needed, but malloc() is obsolete.
  40.  
  41. Kurt
  42. --
  43. | Kurt Watzka                             Phone : +49-89-2180-6254
  44. | watzka@stat.uni-muenchen.de
  45. | ua302aa@sunmail.lrz-muenchen.de
  46.  
  47.